package command

import (
	"alarm_service/common/logger"
	"alarm_service/internal/dto"
	"alarm_service/internal/repo/command"
	"fmt"
	"net"
)

type CommandCase struct {
	command.Repo
}

func New(cr command.Repo) *CommandCase {
	s := &CommandCase{
		Repo: cr,
	}
	return s
}

func (s *CommandCase) SetPhone(params dto.PhoneReq, conn net.Conn) {
	phoneStr := ""
	for _, phone := range params.Phones {
		phoneStr += phone
	}
	pushData := fmt.Sprintf("SA%sE", phoneStr)
	_, err := conn.Write([]byte(pushData))
	if err != nil {
		logger.Errorf("[SetPhone] push data error %v", err)
	}
}

func (s *CommandCase) SetMessageSwitch(params dto.MessageSwitchReq, conn net.Conn) {
	pushData := fmt.Sprintf("SB%dE", params.DeviceMessageSwitch)
	conn.Write([]byte(pushData))
}

func (s *CommandCase) SetRecover(params dto.RecoverReq, conn net.Conn) {
	pushData := fmt.Sprintf("SC%dE", 1)
	conn.Write([]byte(pushData))
}

func (s *CommandCase) SetPhoneSwitch(params dto.PhoneSwitchReq, conn net.Conn) {
	pushData := fmt.Sprintf("SF%dE", params.DevicePhoneSwitch)
	conn.Write([]byte(pushData))
}
